<html>
<head><meta charset="utf-8"><title>basic `#[target_feature]` optimizations · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html">basic `#[target_feature]` optimizations</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="171840969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171840969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171840969">(Jul 27 2019 at 11:10)</a>:</h4>
<p><span class="user-mention" data-user-id="133224">@Nikita Popov</span> I was thinking of taking a stab at this: <a href="https://bugs.llvm.org/show_bug.cgi?id=41138" target="_blank" title="https://bugs.llvm.org/show_bug.cgi?id=41138">https://bugs.llvm.org/show_bug.cgi?id=41138</a></p>



<a name="171841046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841046">(Jul 27 2019 at 11:13)</a>:</h4>
<p>A super common problem users using the <code>core::arch</code> intrinsics have is that, when abstracting over the intrinsics, they put them behind functions that aren't <code>#[target_feature]</code>. This prevents inlining - inlining across different target features is a bad idea -, which ends up meaning that, e.g., SIMD vectors end up spilled to the stack across each intrinsic</p>



<a name="171841096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841096">(Jul 27 2019 at 11:14)</a>:</h4>
<p>I think that even the most basic LLVM pass here would be incredibly valuable</p>



<a name="171841189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841189">(Jul 27 2019 at 11:17)</a>:</h4>
<p>If a function is called unconditionally, and that function has target features, add those target features to the caller.</p>



<a name="171841239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841239">(Jul 27 2019 at 11:18)</a>:</h4>
<p>recursively traversing all functions, updating their target features through the call stack</p>



<a name="171841593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841593">(Jul 27 2019 at 11:27)</a>:</h4>
<p>The intrinsics shouldn't have #[target_feature], and should always be inlined</p>



<a name="171841797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841797">(Jul 27 2019 at 11:33)</a>:</h4>
<p>At least if LLVM handles them correctly, which I hope it does since C/C++ does not have a <code>target_feature</code> feature.</p>



<a name="171841866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841866">(Jul 27 2019 at 11:35)</a>:</h4>
<p>If the intrinsics don't have <code>#[target_feature]</code> then they generate incorrect codegen</p>



<a name="171841873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841873">(Jul 27 2019 at 11:35)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> of course C and C++ have a target-feature feature __((target_feature = "foo"))__ or something like that</p>



<a name="171841878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841878">(Jul 27 2019 at 11:35)</a>:</h4>
<p>whether the intrinsics should be inlined is also up to the optimizer</p>



<a name="171841919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841919">(Jul 27 2019 at 11:36)</a>:</h4>
<p>some of them are quite complex and not worth inlining</p>



<a name="171841928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171841928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171841928">(Jul 27 2019 at 11:36)</a>:</h4>
<p>Why do they generate incorrect code? That makes no sense</p>



<a name="171843026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843026">(Jul 27 2019 at 12:13)</a>:</h4>
<p>The pass you likely want to change is the <a href="https://llvm.org/docs/Passes.html#functionattrs-deduce-function-attributes" target="_blank" title="https://llvm.org/docs/Passes.html#functionattrs-deduce-function-attributes">functionattrs pass</a>.</p>



<a name="171843030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843030">(Jul 27 2019 at 12:13)</a>:</h4>
<p>Actually no, you want traversion in a reversed order than what functionattrs does.</p>



<a name="171843071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843071">(Jul 27 2019 at 12:14)</a>:</h4>
<p>Wait, no, from your description it appears that functionattrs is exactly what you want</p>



<a name="171843441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843441">(Jul 27 2019 at 12:27)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> the pass needs to track whether it has already been applied to a function, and when it sees an unconditonal function call,  if it hasn't been applied to it, then recurse down first</p>



<a name="171843450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843450">(Jul 27 2019 at 12:27)</a>:</h4>
<blockquote>
<p>If a function is called unconditionally, and that function has target features, add those target features to the caller.</p>
</blockquote>
<p>Is what functionattrs will allow you to implement</p>



<a name="171843474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843474">(Jul 27 2019 at 12:28)</a>:</h4>
<p>this is the same thing it does for readnone/readonly/etc attributes.</p>



<a name="171843501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843501">(Jul 27 2019 at 12:28)</a>:</h4>
<blockquote>
<p>Why do they generate incorrect code? That makes no sense</p>
</blockquote>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span>  Because if they don't have target-features, the llvm intrinsics they call cannot be inlined across them, and everything gets spilled to the stack</p>



<a name="171843502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843502">(Jul 27 2019 at 12:28)</a>:</h4>
<p>i.e. this pass goes from leaves of the trees up to the root (<code>main</code>).</p>



<a name="171843507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843507">(Jul 27 2019 at 12:28)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> perfect, that's exactly what i need here</p>



<a name="171843516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843516">(Jul 27 2019 at 12:29)</a>:</h4>
<p>i'm not sure if I should duplicate the pass, or modify it</p>



<a name="171843566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843566">(Jul 27 2019 at 12:30)</a>:</h4>
<p>I can add options to it, I think i will do that first</p>



<a name="171843641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843641">(Jul 27 2019 at 12:33)</a>:</h4>
<p>It depends on whether it makes sense to have this pass separately enabled from the rest of the stuff functionattrs do.</p>



<a name="171843644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843644">(Jul 27 2019 at 12:33)</a>:</h4>
<p>(likely not)</p>



<a name="171843650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843650">(Jul 27 2019 at 12:33)</a>:</h4>
<p>i think that this pass is always sound</p>



<a name="171843891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171843891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171843891">(Jul 27 2019 at 12:40)</a>:</h4>
<p>I'm just afraid that C code is not, and that this pass will break it hard</p>



<a name="171844373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171844373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171844373">(Jul 27 2019 at 12:56)</a>:</h4>
<p>LLVM does not concern itself with code that’s UB.</p>



<a name="171844881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171844881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171844881">(Jul 27 2019 at 13:12)</a>:</h4>
<p>LLVM is moving to the Attributor framework (<a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/IPO/Attributor.cpp" target="_blank" title="https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/IPO/Attributor.cpp">https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/IPO/Attributor.cpp</a>) for attribute inference. I'm not totally sure what the current state there is and whether new additions to FunctionAttrs are accepted at this point.</p>



<a name="171845208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845208">(Jul 27 2019 at 13:23)</a>:</h4>
<p>To propagate target features you need that every path from the entry is guaranteed to hit a target feature call -- which is usually approximated as it being in the entry block and having only guaranteed-transfer instructions before it.</p>



<a name="171845506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845506">(Jul 27 2019 at 13:32)</a>:</h4>
<p>I was looking at the attributor framework, and at the Attribute class, but it is not clear to me how target-specific attributes are handled there</p>



<a name="171845682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845682">(Jul 27 2019 at 13:39)</a>:</h4>
<p><span class="user-mention" data-user-id="133224">@Nikita Popov</span> is it possible to iterate over all calls that are guaranteed to be hit from the entry ?</p>



<a name="171845824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845824">(Jul 27 2019 at 13:43)</a>:</h4>
<p>i'm not sure whether attributor or FunctionAttrs is a better place for the pass</p>



<a name="171845837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845837">(Jul 27 2019 at 13:43)</a>:</h4>
<p>AFAICT attributor would try to recompute the target-feature attribute of a function until a fix-point is reached</p>



<a name="171845883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171845883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171845883">(Jul 27 2019 at 13:44)</a>:</h4>
<p>i'm not sure from reading into the framework whether the attribute of the functions being called are computed before  those of the callee or not</p>



<a name="171846057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171846057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171846057">(Jul 27 2019 at 13:49)</a>:</h4>
<p>and indeed the functionality of the FunctionAttributes appears to be replicated in Attributor already</p>



<a name="171847740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171847740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171847740">(Jul 27 2019 at 14:37)</a>:</h4>
<p>I don't think there's anything for the guaranteed-execution case yet -- a good starting point would be to loop over the instructions in the entry block until <code>isGuaranteedToTransferExecutionToSuccessor()</code> returns false. May be enhanced by checking in-flight attributes (like willreturn), which is where the fixpoint iteration comes in, as you will now depend on the overall attributor state.</p>



<a name="171979230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/171979230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#171979230">(Jul 29 2019 at 20:10)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> It looks like the necessary tooling for this is being worked on right now (see for example <a href="https://reviews.llvm.org/D65186" target="_blank" title="https://reviews.llvm.org/D65186">https://reviews.llvm.org/D65186</a> and <a href="https://reviews.llvm.org/D65402" target="_blank" title="https://reviews.llvm.org/D65402">https://reviews.llvm.org/D65402</a>), so it probably makes sense to wait a bit until it is in place.</p>



<a name="172023422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/172023422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#172023422">(Jul 30 2019 at 10:09)</a>:</h4>
<p>Thanks, it appears that jdoerfert is the person to ping about this.</p>



<a name="172023475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/basic%20%60%23%5Btarget_feature%5D%60%20optimizations/near/172023475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/basic.20.60.23.5Btarget_feature.5D.60.20optimizations.html#172023475">(Jul 30 2019 at 10:10)</a>:</h4>
<p>It's also unclear to me how to access target-specific attributes from the Attributor framework</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>